#!/usr/bin/env python
import json
import sys
import class_set
from sets import Set

def node_overlap(node, dict):
    if node in dict:
        return True
    else:
        return False

def node_overtime(nodea, nodeb):
    if nodea.time > nodeb.time:
        return True
    else:
        return False

def parse_json(line):
    node_operator = json.loads(line)
    uid = node_operator["uid"]
    addtime = node_operator["addtime"]
    staruids = node_operator["staruids"]
    type = node_operator["type"]
    return (uid, addtime, staruids, type)

def main():
    hash_table = {}
    for line in sys.stdin:
        uid, addtime, staruids, type = parse_json(line)

        if not node_overlap(uid, hash_table):
            hash_table[uid] = {}

        for node_id in staruids:
            """
            initial process for center node
            """
            other_node = UserNode(node_id, addtime, type)
            if not node_overlap(node_id, hash_table[uid]):
                hash_table[uid][node_id] = other_node
            elif node_overtime(other_node, hash_table[uid][node_id]):
                hash_table[uid][node_id] = other_node
            else:
                pass

            """
            second process for other nodes
            """
            if not node_overlap(node_id, hash_table):
                hash_table[node_id] = {}
            center_node = None
            new_type = None
            if type == "addattention":
                new_type = "beaddfan"
            elif type == "delstars":
                new_type = "bedelfan"
            elif type == "delfans":
                new_type == "bedelstar"
            center_node = UserNode(uid, addtime, new_type)
            if not node_overlap(uid, hash_table[node_id]):
                hash_table[node_id][uid] = center_node
            elif node_overtime(center_node, hash_table[node_id][uid]):
                hash_table[node_id][uid] = center_node
            else:
                pass

    for node in hash_table:
        print node
        print hash_table[node]

if __name__ == '__main__':
    main()




